SWEP.Base = "weapon_ic_util_stickbase"

if SERVER then
	AddCSLuaFile ("shared.lua")
end

SWEP.Spawnable				= true

SWEP.PrintName			= "HEALSTICK"
SWEP.Description		= "A tool designed partially on what appears to be arcane magic. Heals allied targets at a range of multiple metres, at a rapid rate, but deals no damage to enemies."
SWEP.BeamColour = Color(0, 255, 0)

// Stuff that needs to be here...
SWEP.Cost				= 0
SWEP.Slot				= 3
SWEP.IconFont				= "HL2MPTypeDeath"
SWEP.IconLetter				= "!"


SWEP.Primary.Sound			= Sound ("Airboat_fan_idle")

SWEP.HealDelay = 0.2
SWEP.HealAmount = 5

SWEP.RechargeDelay = 2
SWEP.RechargeAmount = 5
SWEP.RechargeUpto = 100
SWEP.Primary.DefaultClip	= 101
SWEP.Primary.ClipSize	= -1

if CLIENT then killicon.AddFont("weapon_ic_healstick", SWEP.IconFont, SWEP.IconLetter, Color(255, 80, 0, 255)) end

function SWEP:DoFire()
	local trace = util.QuickTrace( self.Owner:GetShootPos(), self.Owner:GetAimVector() * 192, self.Owner )
	if ( IsValid( trace.Entity ) and trace.Entity:IsPlayer() ) then
		local ply = trace.Entity
		local health = ply:Health()
		local heal = math.min( math.min( 100 - health, self.HealAmount ), self:Ammo() )
		if ( heal > 0 ) then
			ply:SetHealth( health + heal )
			self:TakePrimaryAmmo( heal )
			GAMEMODE:CallHook( "PlayerHeal", self.Owner, ply, heal )
		end
	end
end

function SWEP:DrawHUD()
	local localPly = LocalPlayer()
	if !IsValid(localPly) then return end
	
	local w, h = ScrW(), ScrH()
	local size = math.min(w, h) * 0.4
	local x, y = w / 2, h / 2
	
	local bw, bh = ScrW() / 40, ScrW() / 160
	
	for _, ply in pairs(player.GetAll()) do
		if ply != localPly && ply:Alive() then
			local ang = (ply:GetPos() - EyePos()):Angle() - EyeAngles()
			ang.p, ang.r = 0, 0
			ang.y = ang.y + 90
			local add = ang:Forward() * size
			local nx, ny = x - add.x, y - add.y
			
			local f, o = HUD_BOX_COLOUR, HUD_LINE_COLOUR
			
			surface.SetDrawColor(f.r, f.g, f.b, f.a)
			surface.DrawRect(nx - bw, ny - bh, bw * 2, bh * 2)
			draw.SimpleText(ply:Health(), "Default", nx, ny, Color(255, 255, 255), TEXT_ALIGN_CENTER)
		end
	end
end